package com.chenglu.android.order.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chenglu.android.R;
import com.chenglu.android.common.utils.Utils;
import com.chenglu.android.order.bean.OrderInfoBean;


import java.util.List;

/**
 * @author: lyj
 * @Created: by Copyright 2023/3/29 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description：我的全部订单item
 */
public class AllOrderItemAdapter extends BaseQuickAdapter<OrderInfoBean.Data.Records.OrderDetails, BaseViewHolder> {
     Context mContext;

    public AllOrderItemAdapter(Context context, int layoutResId, @Nullable List<OrderInfoBean.Data.Records.OrderDetails> data) {
        super(layoutResId, data);
        this.mContext = context;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, OrderInfoBean.Data.Records.OrderDetails item) {
        helper.setText(R.id.tv_cart_goodsName, item.getGoodsVO().getGoodsName()); //商品名称

        if(item.getGoodsVO().getGoodsSkus().isEmpty()){
            helper.setVisible(R.id.tv_cart_goodsSpec,false);
        }else {
            helper.setVisible(R.id.tv_cart_goodsSpec,true);

             String datas = item.getGoodsVO().getGoodsSkus().get(0).getSpec().replace("{" ,"")
                     .replace("}","").replaceAll("\""," ");
//            Spec spec = com.alibaba.fastjson.JSONObject.parseObject(datas, Spec.class);

            helper.setText(R.id.tv_cart_goodsSpec,  datas); //规格
        }

         ImageView imageView = helper.getView(R.id.iv_cart_goodsImg);
         Glide.with(mContext).load(item.getGoodsVO().getGoodsImg()).into(imageView);

         //全部订单不显示
        helper.setVisible(R.id.tv_cart_goodsTotalPrice,false);

        TextView  tvmoney =  helper.getView(R.id.tv_cart_goodsTotalPrice);//显示商品价格

        tvmoney.setText("¥" +Utils.formatZeroNumber(item.getGoodsVO().getGoodsPayPrice()) );
//        Utils.goodsType(item.getGoodsVO().getGoodsType(),tvmoney,item.getGoodsVO().getGoodsPriceTotal());

        //商品数量
        helper.setText(R.id.tv_cart_goodsNum, "" + "共"+item.getGoodsAmount()+"件");


        helper.setText(R.id.tv_order_sum, "" + "合计："+item.getGoodsVO().getGoodsPrice());

        RelativeLayout relativeLayout = helper.getView(R.id.rl_cart_gift);
        relativeLayout.setVisibility(View.GONE);//赠品不显示

        helper.addOnClickListener(R.id.rv_cart_goosImg); //点击事件

    }
}
